package eu.sudparis.it.opp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class TimeSeries {
	public HashMap<Long, List<Event>> line = new HashMap<Long, List<Event>>();
	public long max_time = 0;
	public long min_time = 0;
	public int max_id = 0;
	public int min_id = 0;
	public Graph graph;
	public boolean sync=true;
	public long currentTime;
	public Interceptor interceptor;

	
	
	public HashMap<Long, List<Event>> getLine() {
		return line;
	}

	public void setLine(HashMap<Long, List<Event>> line) {
		this.line = line;
	}

	public long getMax_time() {
		return max_time;
	}

	public void setMax_time(long max_time) {
		this.max_time = max_time;
	}

	public long getMin_time() {
		return min_time;
	}

	public void setMin_time(long min_time) {
		this.min_time = min_time;
	}

	public int getMax_id() {
		return max_id;
	}

	public void setMax_id(int max_id) {
		this.max_id = max_id;
	}

	public int getMin_id() {
		return min_id;
	}

	public void setMin_id(int min_id) {
		this.min_id = min_id;
	}

	public Graph getGraph() {
		return graph;
	}

	public void setGraph(Graph graph) {
		this.graph = graph;
	}

	public long getCurrentTime() {
		return currentTime;
	}

	public void setCurrentTime(long currentTime) {
		this.currentTime = currentTime;
	}

	public void attachEvent(long num, Event eve) {
		if (line.containsKey(num)) {
			if(line.get(num).contains(eve))
				return;
			line.get(num).add(eve);
		} else {
			ArrayList<Event> arr = new ArrayList<Event>();
			arr.add(eve);
			line.put(num, arr);
		}
	}

	public void run() {
		if(this.interceptor!=null)
			this.interceptor.init(this);
		for (long i = min_time; i <= max_time; i++) {
			this.currentTime=i;
			if(this.interceptor!=null)
				this.interceptor.before(this);
			if (line.containsKey(i)) {
				for (Event eve : line.get(i)) {
					graph.travelGraph(eve);
				}
			}
			if(this.interceptor!=null)
				this.interceptor.after(this);
		}
		if(this.interceptor!=null)
			this.interceptor.fini(this);
	}
}
